package com.tedu.API.homeWork;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.*;
import java.util.List;
import java.util.stream.Collectors;


public class homework1 {

    public static void main(String[] args) {
        //创建list
        List<worker> list = new ArrayList<>();
        //创建王克张的对象,并且添加到list
        zhangMT zhang =new zhangMT("张孟涛",18,1800);
        list.add(new wangKe("王克",21,2100));
        list.add(zhang);
        //使用迭代器遍历
        Iterator<worker> it = list.iterator();
        while (it.hasNext()) {
            Object o = it.next();
            System.out.println(o);
        }
        //需求：计算薪资平均值，stream()
        double workSalaryAver = list.stream()
                .mapToDouble(worker -> worker.getSalary())
                .average().orElse(0.0);
        //可以了  1.worker可以做为泛型    2.zhangMT中没有getSalary方法
        System.out.println("平均薪资"+workSalaryAver);

        //打印输出王*
        //取出对象，循环，contains
        //定义一个获取键盘对象
        Scanner scanner=new Scanner(System.in);
        String str=scanner.next().trim();

        //取出name元素
         List<String> workerName=list.stream()
                .map(worker->worker.getName())
                 .collect(Collectors.toList());
         //字符串转换为字符数组，
       for (int i=0;i<workerName.size();i++){
            //转换数组，取出数组[0]
           byte[] b=workerName.get(i).getBytes(StandardCharsets.UTF_8);  //“张” “孟”
           if (str.equals(b)){
               //问题：1.如何输出对应的信息
               System.out.println("所有姓张的信息"+list);

           }else{
               System.out.println("查无此人");
           }
       }

       //输入一个工资，查询工资 大于 输入工资的员工信息。
        //获取输入
        int inquire=scanner.nextInt();
       //获取工资
        List<Integer> salaryInquire=list.stream()
                .map(worker->worker.getSalary())
                .collect(Collectors.toList());
        //循环遍历，判断是否相同
        for (int i = 0; i<salaryInquire.size(); i++){
            if (inquire==salaryInquire.get(i)){
                System.out.println("符合薪资工人的薪资");
            }else{
                System.out.println("查无此人");
            }
        }

        //关闭Scanner
        scanner.close();
    }
}

class worker {
    private String name;
    private int year;
    private int salary;
    //构造函数


    public worker(String name, int year, int salary) {
        this.name = name;
        this.year = year;
        this.salary = salary;
    }

    public worker() {
    }
    //set和get


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getSalary() {
        return salary;
    }

    public void setSalary(int salary) {
        this.salary = salary;
    }
}

class zhangMT extends worker {

    private int salary;




    @Override
    public int getSalary() {
        return salary;
    }

    @Override
    public void setSalary(int salary) {
        this.salary = salary;
    }

    public zhangMT(String name, int year, int salary) {
        super(name, year, salary);

        System.out.println(name + " " + year + " " + salary);
    }


}


class wangKe extends worker {
    String name="王";
    int year=18;
    int salary=2100;

    @Override
    public int getSalary() {
        return salary;
    }

    public wangKe(String 王克, int year, int salary) {
    }

    public String toString() {
        return name + salary + year;
    }


}


